package org.abc.fund.entity.factorEntity;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 衍生因子实体类
 */
@Entity
@Table(name = "derived_factors")
@Data
@EqualsAndHashCode(callSuper = false)
public class DerivedFactor {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    /**
     * 衍生因子代码
     */
    @Column(unique = true, nullable = false, length = 100)
    private String factorCode;
    /**
     * 衍生因子名称
     */
    @Column(nullable = false, length = 200)
    private String factorName;
    /**
     * 因子描述
     */
    @Column(columnDefinition = "TEXT")
    private String description;
    /**
     * 计算公式（JSON格式）
     */
    @Column(columnDefinition = "TEXT", nullable = false)
    private String formula;
    /**
     * 是否启用
     */
    @Column(nullable = false)
    private Boolean enabled = true;

    public String getOperator() {
        return operator;
    }
    public void setOperator(String operator) {
        this.operator = operator;
    }
    /**
     * 算子
     */
    @Column(nullable = false)
    private String operator;
    /**
     * 创建时间
     */
    @CreationTimestamp
    @Column(nullable = false, updatable = false)
    private LocalDateTime createTime;
    /**
     * 更新时间
     */
    @UpdateTimestamp
    @Column(nullable = false)
    private LocalDateTime updateTime;
    /**
     * 创建人
     */
    @Column(length = 100)
    private String createdBy;
    /**
     * 更新人
     */
    @Column(length = 100)
    private String updatedBy;
    /**
     * 输入因子组件
     */
    @OneToMany(mappedBy = "derivedFactor", cascade = CascadeType.ALL, orphanRemoval = true)
    @JsonManagedReference
    private List<DerivedFactorComponent> components;
    /**
     * 计算频率枚举
     */
    public enum CalculationFrequency {
        DAILY("日频"),
        WEEKLY("周频"),
        MONTHLY("月频"),
        QUARTERLY("季频");

        private final String description;

        CalculationFrequency(String description) {
            this.description = description;
        }

        public String getDescription() {
            return description;
        }
    }
    // ========== 补全getter/setter ==========
    public Long getId() { return id; }
    public void setId(Long id) { this.id = id; }
    public String getFactorCode() { return factorCode; }
    public void setFactorCode(String factorCode) { this.factorCode = factorCode; }
    public String getFactorName() { return factorName; }
    public void setFactorName(String factorName) { this.factorName = factorName; }
    public String getDescription() { return description; }
    public void setDescription(String description) { this.description = description; }
    public String getFormula() { return formula; }
    public void setFormula(String formula) { this.formula = formula; }

    public Boolean getEnabled() { return enabled; }
    public void setEnabled(Boolean enabled) { this.enabled = enabled; }
    public LocalDateTime getCreateTime() { return createTime; }
    public void setCreateTime(LocalDateTime createTime) { this.createTime = createTime; }
    public LocalDateTime getUpdateTime() { return updateTime; }
    public void setUpdateTime(LocalDateTime updateTime) { this.updateTime = updateTime; }
    public String getCreatedBy() { return createdBy; }
    public void setCreatedBy(String createdBy) { this.createdBy = createdBy; }
    public String getUpdatedBy() { return updatedBy; }
    public void setUpdatedBy(String updatedBy) { this.updatedBy = updatedBy; }
    public List<DerivedFactorComponent> getComponents() { return components; }
    public void setComponents(List<DerivedFactorComponent> components) { this.components = components; }

}